<?php
/**
*网关控制器
*/
namespace Home\Controller;
use Think\Controller;
class GatewayController extends CommonController {

//需要输入的所有必要数据，mode是可选的
private $input_arr=array(
"mid"=>"Merchant ID",
"oid"=>"Merchant order ID",
"site_id"=>"Site ID",
"order_amount"=>"Order amount",
"order_currency"=>"Order currency",

"hash_info"=>"Hash info",//sha256 哈希值，用于防止数据在传输过程中被篡改

"card_no"=>"Credit card number",
"card_cvv"=>"Card cvv",
"card_ex_year"=>"Expiry year",
"card_ex_month"=>"Expiry month",

"bill_email"=>"Customer email",
"bill_phone"=>"Customer phone",
"bill_country"=>"Billing country",
"bill_state"=>"Billing state",
"bill_city"=>"Billing city",
"bill_street"=>"Billing street",
"bill_zip"=>"Billing zip",
"bill_firstname"=>"Customer's first name",
"bill_lastname"=>"Customer's last name",
"syn_url"=>"Synchronous notification URL",
"asyn_url"=>"Asynchronous notification URL",

"source_ip"=>"IP address",//新增IP参数
);
//商户信息
private $merchant_info;
//网站信息
private $site_info;
//通道信息
private $channel_info;
//信用卡信息
private $card_info;
//货币信息
private $currency_info;
//国家信息
private $country_info;
//订单示例
private $order_oop;


/**
*网关接口提交处理，包括生成加密字符串和提交接口处理功能
*/
  public function test(){	  
	if(I("type")==1){ 
	//mid+site_id+oid+order_amount+order_currency+site_key
	$input_txt=hash("sha256", I("mid").I("site_id").I("oid").I("order_amount").I("order_currency")."qwertyuiop"); 
	echo "hash info:<br>".$input_txt;
	}else{
	$this->securepay();	
	}
  }
 
  /**
  *测试页面
  */
 public function test_gateway(){
	 //echo floor((0.1+0.7)*10) ;
	 $this->display("index");
 }
 
/**
*网关提交接口
*提交的数据包括 mid,oid,site_id,order_amount,order_currency, hash_info 支付验证信息（6）
* bill_email,bill_phone,bill_country,bill_state,bill_city,bill_street,bill_zip,bill_firstname,bill_lastname 账单人信息（9）
* syn_url,asyn_url 及时通知和异步通知地址（2）
* (card_no,card_cvv,card_ex_year,card_ex_month  支付卡信息（4）
* api_mode (sandbox,production) 沙箱模式和生产模式可选（1）  总计 22个参数,21个必填，1个可选
* hash_info的计算方法为 sha256 mid+site_id+oid+order_amount+order_currency+site_key
*/	
public function securepay(){

	$this->isNullCheck();
	$this->isValidCheck();
	$this->isRealCheck();
	$this->isHashCode();
	$this->isBlacklistCheck();
	$this->isLimitCheck();
	$this->createOrder();
}

/**
* 空值检测	
*/	
private function isNullCheck(){
$data['status']=0;
$data['data']=10006;
foreach($this->input_arr as $key=>$value){
$data['data']++;	
$data['info']=$value." cannot be NULL";
trim(I($key)) || $this->ajaxReturn($data);
}
}

/**
*数据合法性检查	
*/	
private function isValidCheck(){
$data['status']=0;
$data['data']=20001;	
$arr=array(
"order_amount"=>"/^([1-9]\d*)(\.)(\d{2})$/",
"order_currency"=>"/^[A-Z]{3}$/",
"bill_email"=>"/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/",
"bill_country"=>"/^[A-Z]{2}$/",
"source_ip"=>"/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/"
);
foreach($arr as $key=>$value){
$data['data']++;
$data['info']="Invalid ".$this->input_arr[$key];
preg_match($value,I($key)) ||  $this->ajaxReturn($data);	
}


}


/**
* 验证提交的数据的真实性	
*/	
private function isRealCheck(){
$data['status']=0;		
	//商户存在且激活
	$mh_con['mh_isactive']=1;
	$mh_con['mh_id']=I("mid");
	$this->merchant_info=M("merchant")->where($mh_con)->find();
	if(!$this->merchant_info){
	$data['data']=30001;
	$data['info']="Merchant not found";
	$this->ajaxReturn($data);	
	}
	//网站存在且激活
	$site_con['site_mid']=I("mid");
	$site_con["site_isactive"]=1;//已激活
	$site_con["site_id"]=I("site_id");
	$this->site_info=M("site")->where($site_con)->find();
	//echo M("site")->_sql();
	//dump($this->site_info);
	if(!$this->site_info){
	$data['data']=30002;
	$data['info']="Site not found";
	$this->ajaxReturn($data);	
	}
	//货币存在
	$currency_con["ex_currency_name"]=I("order_currency");
	$this->currency_info=M("exchange")->where($currency_con)->find();
	if(!$this->site_info){
	$data['data']=30003;
	$data['info']="Currency not support";
	$this->ajaxReturn($data);	
	}
	//国家存在
	$country_con['countries_iso_code_2']=I("bill_country");
	$this->country_info=M("countries")->where($country_con)->find();
	if(!$this->country_info){
	$data['data']=30004;
	$data['info']="Country not found";
	$this->ajaxReturn($data);	
	}
	//特别的，如果是美国223，加拿大38，澳大利亚13，则州必须是2位
	if($this->country_info['countries_id']==223
	|| $this->country_info['countries_id']==38
	|| $this->country_info['countries_id']==13
	){
		$zone_con['zone_country_id']=$this->country_info['countries_id'];
		$zone_con['zone_code']=I("bill_state");
		$zone_info=M("zones")->where($zone_con)->find();
		//echo M("zones")->_sql();
		//dump($zone_info);
		if(!$zone_info){
			$data['data']=30005;
			$data['info']="State not found";
			$this->ajaxReturn($data);	
		}			
	}
	
//验证邮编
$isZip = \ IsoCodes\ZipCode::validate(I("bill_zip"), I("bill_country"));
if(!$isZip){
$data['data']=20006;
$data['info']="Invalid post code";	
$this->ajaxReturn($data);
}
	
}

/**
*验证加密和哈希码
*/
private function isHashCode(){
	$data['status']=0;	
	//解密signature_info
	$hash_info=hash("sha256",I("mid").I("site_id").I("oid").I("order_amount").I("order_currency").$this->site_info["site_key"]);

	if($hash_info != I("hash_info")){
	$data['data']=30017;
	$data['info']="Invalid hash info";
	$this->ajaxReturn($data);					
	}

	//验证信用卡
	$this->card_info= \Inacho\CreditCard::validCreditCard(I("card_no"));
	if(!$this->card_info['valid']){
	$data['data']=30019;
	$data['info']="Invalid credit card number";
	$this->ajaxReturn($data);					
	}
	//验证CVV
	$cvv_result= \Inacho\CreditCard::validCvc(I("card_cvv"),$this->card_info["type"]);
	if(!$cvv_result){
	$data['data']=30020;
	$data['info']="Invalid cvv";
	$this->ajaxReturn($data);					
	}
	
	//验证过期年月
	 $expiry_date=\Inacho\CreditCard::validDate("20".I("card_ex_year"),I("card_ex_month"));
	
	if(!$expiry_date){
	$data['data']=30021;
	$data['info']="Invalid expiry date";
	$this->ajaxReturn($data);					
	}	
	//exit("over");
	$this->card_info['cvv2']=I("card_cvv");
	$this->card_info['year']=I("card_ex_year");
	$this->card_info['month']=I("card_ex_month");
	$this->card_info['card_holder']=I("bill_firstname").I("bill_lastname");
	
	//dump($this->card_info);exit;
	//验证通道"visa","mastercard","amex","dinersclub","discover","unionpay","jcb"
	switch($this->card_info["type"]){
		case "visa":
			$cn_id=$this->site_info["site_visa"];
			break;
		case "mastercard":
			$cn_id=$this->site_info["site_master"];
			break;
		case "amex":
			$cn_id=$this->site_info["site_amex"];
			break;
		case "dinersclub":
			$cn_id=$this->site_info["site_diners"];
			break;
		case "discover":
			$cn_id=$this->site_info["site_discover"];
			break;
		case "jcb":
			$cn_id=$this->site_info["site_jcb"];
			break;
		default:
	$data['data']=30022;
	$data['info']="Not allowed for the card";
	$this->ajaxReturn($data);						
	}
	
	if(!$cn_id){
	$data['data']=30023;
	$data['info']="Not allowed for the card";
	$this->ajaxReturn($data);					
	}

	//分析通道是否可用
	$cn_con['cn_id']=$cn_id;
	$cn_con['cn_isactive']=1;
	$this->channel_info=M("channels")->where($cn_con)->find();
	if(!$this->channel_info){
	$data['data']=30024;
	$data['info']="Inactive processing channel";
	$this->ajaxReturn($data);					
	}		
}

/**
*	黑名单验证credit card,email,phone,country,ip
*/	
private function isBlacklistCheck(){
	$data['status']=0;		
	$oop=M("blacklist");
	$con1['bl_type']=1;	
	//卡号，MD5后的卡号，sha256哈希之后的卡号
	$con1['bl_value']=['in',[$this->card_info['number'],md5($this->card_info['number']),hash("sha256",$this->card_info['number'])]];
	//$con1['bl_value1']=$this->card_info['cvv2'];
	//$con1['bl_value2']=$this->card_info['year'];
	//$con1['bl_value3']=$this->card_info['month'];
	$result1=$oop->where($con1)->find();
	if($result1){
	$data['data']=40001;
	$data['info']="Fraud card";
	$this->ajaxReturn($data);					
	}			
	
	$con2['bl_type']=2;	
	$con2['bl_value']=I("bill_email");
	$result2=$oop->where($con2)->find();
	if($result2){
	$data['data']=40002;
	$data['info']="Fraud customer";
	$this->ajaxReturn($data);					
	}					
	
	$con3['bl_type']=3;	
	$con3['bl_value']=I("bill_phone");
	$result3=$oop->where($con3)->find();		
	if($result3){
	$data['data']=40003;
	$data['info']="Fraud customer";
	$this->ajaxReturn($data);					
	}		
	
	$con4['bl_type']=4;
	$con4['bl_value']=I("bill_country");
	$result4=$oop->where($con4)->find();
	if($result4){
	$data['data']=40004;
	$data['info']="Fraud country code";
	$this->ajaxReturn($data);					
	}		
	
	$con5['bl_type']=5;	
	$con5['bl_value']=get_client_ip();
	$result5=$oop->where($con5)->find();
	if($result5){
	$data['data']=40005;
	$data['info']="Fraud ip address";
	$this->ajaxReturn($data);					
	}

	/*
	* 商户是否设置IP黑名单
	*/
	$con6['ip_mid']=$this->merchant_info["mh_id"];
	$con6['ip_value']=I("source_ip");
	$result6=M("ipblock")->where($con6)->find();
	if($result6){
	$data['data']=40006;
	$data['info']="IP block";
	$this->ajaxReturn($data);			
	}
	
	/*
	* 商户是否设置国家黑名单
	*/
	$con7['cn_mid']=$this->merchant_info["mh_id"];
	$con7['cn_value']=I("bill_country");
	$result7=M("countryblock")->where($con7)->find();
	if($result7){
	$data['data']=40007;
	$data['info']="Country block";
	$this->ajaxReturn($data);			
	}		
	
}		

/**
*相关限制验证	
*/	
private function isLimitCheck(){
		$data['status']=0;		
	$this->order_oop=M("orders");
	$con['ips_id']=array("neq","[TEST]");
	$con['order_mid']=$this->merchant_info["mh_id"];
	$con1['order_time']=array("like","%".date("Y-m-d")."%");//当日
	$con2['cc_cardid']=$this->card_info["number"];
	
	//单卡日交易次数限制
	if($this->merchant_info['mh_card_daily']!=0){
	$count=$this->order_oop->where($con)->where($con1)->where($con2)->count();
	if($count>=$this->merchant_info["mh_card_daily"]){
		$data['info']="Card daily limited";
		$data["data"]=50001;
		$this->ajaxReturn($data);
	}
	}
	
	//单卡日失败次数
	if($this->merchant_info['mh_card_failed_daily']!=0){
	$con3["order_status"]=6;
	$count=$this->order_oop->where($con)->where($con1)->where($con2)->where($con3)->count();
	if($count>=$this->merchant_info["mh_card_daily"]){
		$data['info']="Failure count daily limited";
		$data["data"]=50002;
		$this->ajaxReturn($data);
	}		
	}
	
	//单卡日成功次数
	if($this->merchant_info['mh_card_success_daily']!=0){
	$con3["order_status"]=2;
	$count=$this->order_oop->where($con)->where($con1)->where($con2)->where($con3)->count();
	if($count>=$this->merchant_info["mh_card_success_daily"]){
		$data['info']="Approved count daily limited";
		$data["data"]=50003;
		$this->ajaxReturn($data);
	}		
	}

	//单用户每天可成功的次数
	if($this->merchant_info['mh_user_daily']!=0){
	$con3["order_status"]=2;
	$con3['order_email']=I("bill_email");
	$count=$this->order_oop->where($con)->where($con1)->where($con3)->count();
	if($count>=$this->merchant_info["mh_user_daily"]){
		$data['info']="User payment count daily limited";
		$data["data"]=50004;
		$this->ajaxReturn($data);
	}		
	}

	//同一个订单号是否允许多次提交	
	if($this->merchant_info['mh_sameid_status']==0){
	$con3['mh_oid']=I("oid");
	$con3['order_siteid']=$this->site_info["site_id"];
	$con3['order_status']=array("neq","5,6");//交易状态不是取消或拒绝
	$count=$this->order_oop->where($con)->where($con1)->where($con3)->count();
	if($count>=1){
		$data['info']="Donot re-send the same order";
		$data["data"]=50005;
		$this->ajaxReturn($data);
	}		
	}
	
	//防止重复订单，同个商户的同一个订单号pending的不允许提交
	$con3['order_status']=1;//交易状态pending
	$count=$this->order_oop->where($con)->where($con1)->where($con3)->count();
	if($count>=1){
		$data['info']="Order in process";
		$data["data"]=50006;
		$this->ajaxReturn($data);
	}	
	
}


/**
*生成订单
*/
private function createOrder(){
	//查看通道货币对应的汇率
	$gateway_currency_info=M("exchange")->where(array("ex_currency_name"=>$this->channel_info['cn_currency']))->find();
	
	/*订单重要信息*/
	$odata['mh_oid']=I("oid");
	//$odata['ips_id']=date("Ymd")."-".$this->channel_info["cn_key1"]."-".date('hms').makePass(4);//订单生成日期(yyyymmdd)-商户编号-商户流水号
	$odata['order_amount']=I("order_amount");
	$odata['order_currency']=I("order_currency");
	$odata['order_source_url']=$_SERVER['HTTP_REFERER']."";
	$odata['order_source_ip']=I("source_ip");
	$odata['order_signature_info']=I("hash_info");
	$odata['order_channel']=$this->channel_info["cn_id"];//支付通道
	$odata['order_bill_desc']=$this->channel_info["cn_desc"];//账单名
	
	//对比传入货币与基准货币
	if($this->currency_info['ex_currency_name']==$this->web_config['web_currency']){
		$tmp=0;
	}else{
		$tmp=$this->merchant_info['mh_sp_exchange'];
	}
	//任意货币兑换1基础货币的汇率*(1-商户汇率比)
	$odata['order_roe']=$this->currency_info["ex_currency_value"]*(1-$tmp);
	
	$odata['base_amount']=$odata['order_amount']/$odata['order_roe'];//平台基础货币金额
	$odata['gateway_currency']=$this->channel_info["cn_currency"];//通道提交货币
	$odata['gateway_roe']=$gateway_currency_info['ex_currency_value'];//通道货币对应的1基础货币的汇率
	$odata['gateway_roe_tpl']=$this->merchant_info["mh_exchange_tpl"];//赚取的汇率差
	$odata['gateway_amount']=$odata['base_amount']*$odata['gateway_roe']*(1+$odata['gateway_roe_tpl']);//通道金额
	$odata['process_mode']=$this->site_info["site_process_mode"];//交易模式，消费或者预授权

	/*信用卡信息*/
	$odata['card_type']=$this->card_info["type"];		
	$odata['cc_cardid']=$this->card_info["number"];
	$odata['cc_cvv']=$this->card_info["cvv2"];
	$odata['cc_expiry_month']=$this->card_info["month"];
	$odata['cc_expiry_year']=$this->card_info["year"];
	$odata['cc_card_holder']=$this->card_info['card_holder'];
	
	/*账单人相关信息*/
	$odata['bill_email']=I("bill_email");
	$odata['bill_country']=I("bill_country");
	$odata['bill_state']=I("bill_state");
	$odata['bill_city']=I("bill_city");
	$odata['bill_street']=I("bill_street");
	$odata['bill_phone']=I("bill_phone");
	$odata['bill_zip']=I("bill_zip");
	$odata['bill_firstname']=I("bill_firstname");
	$odata['bill_lastname']=I("bill_lastname");
	$odata['order_syn_url']=I("syn_url");
	$odata['order_asyn_url']=I("asyn_url");
	
	/*商户，配置及费用信息*/
	$odata['order_mid']=$this->merchant_info["mh_id"];
	$odata['order_rolling_rate']=$this->merchant_info["mh_rolling_rate"];
	$odata['order_rolling_days']=$this->merchant_info["mh_rolling_days"];
	$odata['order_siteid']=$this->site_info["site_id"];
	$odata['order_fixedfee']=$this->merchant_info["mh_process_rate"];
	$odata['order_process_rate']=$this->merchant_info["mh_rolling_rate"];
	$odata['order_refund_fee']=$this->merchant_info["mh_refund_fee"];
	$odata['order_declined_fee']=$this->merchant_info["mh_failed_fee"];
	$odata['order_cb_fee']=$this->merchant_info["mh_cb_fee"];
	
	/*是否周期交易的标志，前一个周期交易的ID号*/
	$odata['order_rebill_id']=I("rebill_id")?I("rebill_id"):0;
	
	//dump($odata);exit;
	$result=$this->order_oop->add($odata);
	if(!$result){
	$data['data']=50001;
	$data['info']="system error";
	$data['status']=0;
	$this->ajaxReturn($data);			
	}

	//写入交易历史
	$oh['oh_oid']=$result;
	$oh['oh_origin_amount']=$odata['order_amount'];
	$oh['oh_amount']=$odata['base_amount'];
	$oh['oh_gateway_amount']=$odata['gateway_amount'];
	$oh['oh_remark']="Transaction created...";
	M("orderhistory")->add($oh);


if(I('mode')=="sandbox" || I(3)=="sandbox"){//沙箱环境，测试URL
//更新交易为测试
$sandbox['order_id']=$result;
$sandbox['ips_id']="[TEST]";
$sandbox['order_status']=2;//成功
$this->order_oop->save($sandbox);

$order_data['order_status']=2;
$order_data['order_id']=$result;
}else{
//判断是否存在代理商，并写入相应的信息
$this->createResellerOrder($odata['order_mid'],$result,$odata['base_amount']);	
//dump($this->channel_info);
$order_list=$this->order_oop->find($result);
//dump($this->channel_info);exit;
$order_data=A($this->channel_info['cn_name'])->process($this->channel_info,$this->site_info,$order_list);//返回支付状态和失败原因(可选)
$order_data['order_id']=$result;
}
if($order_data){
$this->notify_method($order_data);	
}else{
	$data['data']=50002;
	$data['info']="processing bank error";
	$data['status']=0;
	$this->ajaxReturn($data);				
}	
}

/**
*订单通知
*/
private function notify_method($order_data){
$o_arr['order_status']=$order_data['order_status'];
$o_arr['oid']=I("oid");
$o_arr['pid']=(int)$order_data['order_id'];
$o_arr['order_amount']=I('order_amount');
$o_arr['order_currency']=I('order_currency');
$o_arr['hash_info']=I('hash_info');
$o_arr['syn_url']=urlencode(I('syn_url'));

switch($order_data['order_status']){
	case 1://未知状态
	$data['info']='pending pay';
	break;
	case 2://成功
	$data['info']="payment success.";
	break;
	case 3://已授权
	$data['info']="transaction authorized.";
	break;
	case 6://失败
	$data['info']=$order_data['order_failed_reason'];
	break;
}

$data['status']=1;
$data['data']=$o_arr;

$this->ajaxReturn($data);
}

/**
*生成代理商订单列表,无返回值
*@param int $mid 商户ID
*@param int $oid 订单ID
*@param float $amount 订单基础金额
*/
private function createResellerOrder($mid,$oid,$amount){
	$oop=M("affiliateMerchant");
	$list=$oop->where(array("mh_id"=>$mid))->select();
	if($list){
	foreach($list as $key=>$value){
	$aff_data[$key]['aff_id']=$value['aff_id'];
	$aff_data[$key]['order_id']=$oid;
	$aff_data[$key]['aff_rate']=$value['aff_rate'];
	$aff_data[$key]['aff_commission']=$value['aff_rate']*$amount;
	$aff_data[$key]['aff_refund_fee']=$value['aff_refund_fee'];
	$aff_data[$key]['aff_cb_fee']=$value['aff_cb_fee'];
	$aff_data[$key]['aff_failed_fee']=$value['aff_failed_fee'];
	$aff_data[$key]['aff_fixed_fee']=$value['aff_fixed_fee'];
	}
	M("affiliateOrder")->addAll($aff_data);
	}
}

/**
*rebilling交易接口
*@param int pid 前一个平台订单ID，必须是成功或者退款的
*@param string oid 本次交易的ID
*@param decimal order_amount 本次订单金额
*@param string(3) order_currency 订单货币
*@param string hash_info sha256 pid.oid.order_amount.order_currency.site_key
*/
public function rebilling(){
	//比对哈希值
	$data['status']=0;	
	
	//需要输入的所有必要数据
	$input_arr=array(
	"pid"=>"Previous transaction ID",
	"oid"=>"Merchant order ID",
	"order_amount"=>"Order amount",
	"order_currency"=>"Order currency",
	"hash_info"=>"Hash info",
	);
	//echo I("signature_info");exit;
	$data['data']=100006;
	foreach($input_arr as $key=>$value){
	$data['data']++;	
	$data['info']=$value." cannot be NULL";
	trim(I($key)) || $this->ajaxReturn($data);
	}
	//正则表达式验证
	$data['data']=200001;	
	$arr=array(
		"order_amount"=>"/^([1-9]\d*)(\.)(\d{2})$/",
		"order_currency"=>"/^[A-Z]{3}$/"
		);
		foreach($arr as $key=>$value){
			$data['data']++;
			$data['info']="Invalid ".$input_arr[$key];
			preg_match($value,I($key)) ||  $this->ajaxReturn($data);	
		}	
	
	//首先，看看订单是否是存在的
	$oop=D("OrdersView");
	$con['order_id']=I("pid");
	$con['ips_id']=array("neq","[TEST]");//非测试订单
	$con['order_status']=array("in","2,4,7,8");//
	$list=$oop->where($con)->find();
	if(!$list){
		$data['data']=300001;
		$data['info']="invalid transaction ID";
		$this->ajaxReturn($data);
	}
	

	//比对哈希值
	$hash_info=hash("sha256",I("pid").I("oid").I("order_amount").I("order_currency").$list["site_key"]);
	
	if($hash_info!=I("hash_info")){
	$data['data']=400001;
	$data['info']="Invalid hash info";
	$this->ajaxReturn($data);					
	}
	
	//dump($list);
   $hash_info1=hash("sha256",$list["mh_id"].$list["site_id"].I("oid").I("order_amount").I("order_currency").$list["site_key"]);

	
	$curlPost["order_amount"]=I("order_amount");
	$curlPost["order_currency"]=I("order_currency");
	$curlPost["mid"]=$list["mh_id"];
	$curlPost["site_id"]=$list["site_id"];
	$curlPost["oid"]=I("oid");
	$curlPost["hash_info"]=$hash_info1;
	
	$curlPost["card_no"]=$list["cc_cardid"];
	$curlPost["card_cvv"]=$list["cc_cvv"];
	$curlPost["card_ex_year"]=$list["cc_expiry_year"];
	$curlPost["card_ex_month"]=$list["cc_expiry_month"];
	
	$curlPost['bill_firstname']=$list['bill_firstname'];
	$curlPost['bill_lastname']=$list['bill_lastname'];
	$curlPost['bill_street']=$list['bill_street'];
	$curlPost['bill_city']=$list['bill_city'];
	$curlPost['bill_state']=$list['bill_state'];
	$curlPost['bill_country']=$list['bill_country'];
	$curlPost['bill_zip']=$list['bill_zip'];
	$curlPost['bill_phone']=$list['bill_phone'];
	$curlPost['bill_email']=$list['bill_email'];
	
	$curlPost['syn_url']=$list["order_syn_url"];
	$curlPost['asyn_url']=$list["order_asyn_url"];
	$curlPost['source_ip']=$list['order_source_ip'];
	//周期交易特殊标志
	$curlPost['rebill_id']=I("pid");
	
	//dump($curlPost);exit;
	
	$handle=new \Common\Common\GatewayHandle();
	//dump($curlPost);
	$response=$handle->run($curlPost);
	$this->ajaxReturn($response);
}

/**
*测试周期交易的提交
*/
public function testrebill(){
	if(I("type")==1){ 
	//pid|oid|order_amount|order_currency
	$input_txt=hash("sha256",I("pid").I("oid").I("order_amount").I("order_currency")."qwertyuiop"); 
	echo "hash info:<br>".$input_txt;
	}else{
	$this->rebilling();	
	}
}




}

